<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <div id="vuebox" align="center" class="container">
        <table class="table table-bordered">
            <tr>
                <td colspan="5" style="font-size: 30px;text-align: center">回复信息列表</td>
            </tr>
            <tr>
                <td colspan="5">
                    <a href="javascript:void(0)" @click="openAdd()">添加回复</a>
                    <a href="index.html">返回帖子列表</a>
                </td>
            </tr>
            <tr style="text-align: center">
                <td>回复内容</td>
                <td>回复昵称</td>
                <td>发布时间</td>
            </tr>
            <tr style="text-align: center" v-for="(item,index) in detaillist.pageinfo">
                <td>{{item.content}}</td>
                <td>{{item.author}}</td>
                <td>{{item.createdate}}</td>
            </tr>
        </table>
        <div align="center">
            <ul class="pagination pagination-sm" v-show="detaillist.pageinfo!=null">
                <!--上一页-->
                <li :class="{disabled: !detaillist.hasPrePage}">
                    <a href="javascript:void(0)" v-if="detaillist.hasPrePage" @click="inpage(detaillist.prePage)">&laquo;</a>
                    <a href="javascript:void(0)" v-else >&laquo;</a>
                </li>
                <!--页数跳转-->
                <li v-for="i in detaillist.navigatepageNums" :class="{active :i==pageNum}">
                    <a href="javascript:void(0)" @click="inpage(i)">{{i}}</a>
                </li>
                <!--下一页-->
                <li :class="{disabled: !detaillist.hasNextPage}">
                    <a href="javascript:void(0)" v-if="detaillist.hasNextPage" @click="inpage(detaillist.nextPage)">&raquo;</a>
                    <a href="javascript:void(0)" v-else>&raquo;</a>
                </li>
            </ul>
        </div>
        <!-- 模态框（Modal） -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="myModalLabel">回复</h4>
                    </div>
                    <div class="modal-body">
                        <label for="content">回复内容</label>
                        <textarea id="content" class="form-control" v-model="detail.content" rows="3" maxlength="255"  style="resize:none;" placeholder="回复信息在此输入哦~"></textarea>
                        <hr/>
                        <label for="author">回复昵称</label>
                        <input type="text" id="author" v-model="detail.author" placeholder="输入您的大名!" class="form-control"/>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" @click="Add()" class="btn btn-primary">提交</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    var vm=new Vue({
        el:"#vuebox",
        data:{
            title:null,
            pageNum:1,
            pageSize:3,
            detail:{content:null,author:null},
            detaillist:[]
        },
        mounted(){
            this.querydetail();
        },
        watch:{
        },
        methods:{
            //贴纸列表
            querydetail:function(){
                axios({url:"/det/list", method:"get",
                    params:{pageNum:this.pageNum,pageSize:this.pageSize}})
                    .then(res=> {
                        this.detaillist = res.data;
                });
            },
            //打开模态框
            openAdd:function () {
                $('#myModal').modal('show');
            },
            //添加回复
            Add:function () {
                axios.post("/det/add",this.detail).then(res=>{
                    if(res.data.detail!=null){
                        this.querydetail();
                        this.detail={content:null,author:null}
                        $('#myModal').modal('hide');
                        alert("添加成功");
                    }else{
                        alert("添加失败!请联系管理员.");
                    }
                })
            },
            inpage:function (num) {
                this.pageNum=num;
                this.querydetail();
            }
        }
    });
</script>